package web.servlet;

import domain.Category;
import domain.Product;
import jakarta.servlet.ServletException;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.servlet.http.HttpSession;
import service.CatelogService;

import java.io.IOException;
import java.util.List;

public class CategoryFormServlet extends HttpServlet {

    private CatelogService catelogService;

    private static final String CATEGORY_FORM = "/WEB-INF/jsp/catalog/Catagory.jsp";

//    @Override
//    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
//        super.doPost(req, resp);
//    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String categoryId= req.getParameter("categoryId");
        catelogService=new CatelogService();
        Category category=catelogService.getCategory(categoryId);
        List<Product> productList=catelogService.getProductListByCategory(categoryId);
        HttpSession session=req.getSession();
        session.setAttribute("category",category);
        session.setAttribute("productList",productList);
        req.getRequestDispatcher(CATEGORY_FORM).forward(req,resp);

    }
}
